<template>
  <transition>
    <view class="popup-container" v-if="isVisible">
      <view class="popup-background" @click="handleClick"></view>
      <view class="popup-content">
        <slot></slot>
      </view>
    </view>
  </transition>
</template>

<script setup lang="ts">

interface Props {
  isVisible: boolean;
  isOpenEmitVisible: boolean;
}

const props = withDefaults(defineProps<Props>(), {
  isVisible: false,
  isOpenEmitVisible: false
});

const emit = defineEmits(["clickBackground", 'update:isVisible']);

const handleClick = () => {
  props.isOpenEmitVisible && emit('update:isVisible', !props.isVisible);
  emit('clickBackground');
}
</script>

<style lang="scss" scoped>
.popup-container {
  width: 100vw;
  height: 100vh;
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  top: 0;
  left: 0;
  z-index: 999 !important;
  user-select: none;
  touch-action: none;

  .popup-background {
    position: absolute;
    background-color: rgba($color: #000000, $alpha: 0.7);
    width: 100%;
    height: 100%;
    animation-name: backgroundAppear;
    animation-duration: 0.4s;
    animation-fill-mode: both;
    animation-timing-function: cubic-bezier(0.5, 1.21, 0.88, 1.01);
  }

  .popup-content {
    animation-name: contentAppear;
    animation-duration: 0.4s;
    animation-fill-mode: both;
    animation-timing-function: cubic-bezier(0.5, 1.21, 0.88, 1.01);
    display: inline-block;
  }
}

@keyframes backgroundAppear {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes contentAppear {
  from {
    transform: scale(0);
  }

  to {
    transform: scale(1);
  }
}

.v-enter-active,
.v-leave-active {
  transition: opacity 0.2s ease;
}

.v-enter-from,
.v-leave-to {
  opacity: 0;
}
</style>
